<?php
/**
 *
 * ==============================================
 * Copy right 2015-2016 http://wei.meididi88.com
 * ----------------------------------------------
 * This is not a free software, without any authorization is not allowed to use and spread.
 * ==============================================
 * @author: hy
 * @date: 2015-9-10
 * @version: v1.0.0
 */

namespace Common\Model;

use Think\Model;

/**
 * 资讯速递 Model模型类
 */
class ArticleModel extends Model{
	
	protected $_validate = array(
		array('title','require','咨询速递标题不能为空'),
		array('article_desc','require','资讯速递描述不能为空'),
		array('content','require', '资讯速递内容不能为空'),
		array('img_path','require','登录密码必须填写！'),
	);
	
	protected $autoCheckFields = false;
	
	protected $_auto = array(
		 array('created','time',1,'function')
	);
	
	/**
	 * 清空缓存
	 * @param number $id
	 */
	public function clearCache($id) {
		$cacheKey = $this->getCacheKey($id);
		S($cacheKey, null);
	}
	
	/**
	 * 读取服务信息
	 * 
	 * @param number $id	文章编号
	 * @return boolean|array
	 */
	public function getArticleInfo($id) {
		$cacheKey = $this->getCacheKey($id);
		$info = S($cacheKey);
		if (!$info) {
			$info = $this->where(array('id' => $id))->find();
			S($cacheKey, $info);
		}
		return $info;
	}
	
	/**
	 * 缓存key
	 * 
	 * @param number $id
	 * @return string
	 */
	public function getCacheKey($id) {
		return 'Article_Info_'.$id;
	}
}

?>